import { setOauthHeaders } from '@/constants/header';
import HttpConfig from '@/constants/http.config';
import { ContainerEntity } from '@/models/container_entity';
import { TaroFetch } from '@/utils/fetch';
import { RepoModules,DeployModules } from 'types/deploy';
const _fetch=new TaroFetch()
class DeployService {
    async getList(params: {
        pipeline_id?: string;
        repository_id?: string;
        pageIndex: number;
        pageSize: number;
        developer_assign_status?: number;
    }) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/deploy/list`,
            data: params,
            header:options.headers
        }).then((result) => {
            return result.data as  DeployModules.Root
        }) 
    }
    /** 审批执行发布计划  */
    async run(id: string) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/deploy/run/play`,
            data: {
                id,
            },
            header:options.headers
        }).then((result) => {
            return result.data as RepoModules.res_list
        })
    }
    /** 删除申请请求数据 */
    async delete(id: string) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/deploy/delete`,
            data: {
                id,
            },
            method:'POST',
            header:options.headers,
        }).then((result) => {
            return new ContainerEntity<boolean>(result.data)
        })
    }
}

export const deployService = new DeployService()